//
//  MatchDetailViewController.m
//  MyDIYHouse
//
//  Created by dlios on 15-6-30.
//  Copyright (c) 2015年 李平洋. All rights reserved.
//

#import "MatchDetailViewController.h"
#import "MatchDetailTableViewCell.h"
#import "HTTPTool.h"
#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
#import "MatchModel.h"

#define HEIGHT [UIScreen mainScreen].bounds.size.height
#define WIDTH [UIScreen mainScreen].bounds.size.width

@interface MatchDetailViewController ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, retain)UITableView *matchDetailTableView;
@property(nonatomic, retain)UIView *headerView;

//设计师头像按钮
@property(nonatomic, retain)UIButton *headButton;
//设计师名称
@property(nonatomic, retain)UILabel *stylistName;
//房屋大图片
@property(nonatomic, retain)UIImageView *homeImageView;

@property(nonatomic, retain)NSMutableArray *matchDetailArray;
//几个参数写成属性
@property(nonatomic, copy)NSString *user;



@end

@implementation MatchDetailViewController

- (void)dealloc {
    [_matchDetailTableView release];
    [_headerView release];
    [super dealloc];
    
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.matchDetailArray = [NSMutableArray array];
        self.user = @"(null)";
        self.matchModel = [[MatchModel alloc] init];
        
        
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"美图详情";
    self.navigationController.navigationBar.barTintColor = [UIColor brownColor];
    
    
    //#pragma mark 创建titleLabel,实现标题颜色调整
    //    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 44)];
    //    titleLabel.text = @"美图详情";
    //    titleLabel.textColor = [UIColor whiteColor];
    //    titleLabel.textAlignment = NSTextAlignmentCenter;
    //    self.navigationItem.titleView = titleLabel;
    
#pragma mark 系统自带的修改title的字体颜色的方法 然并不推荐使用
    UIColor * color = [UIColor whiteColor];
    NSDictionary * dict=[NSDictionary dictionaryWithObject:color forKey:UITextAttributeTextColor];
    self.navigationController.navigationBar.titleTextAttributes = dict;
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
#pragma mark 创建tableView
    self.matchDetailTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64 - 49 ) style:UITableViewStylePlain];
    self.matchDetailTableView.delegate = self;
    self.matchDetailTableView.dataSource = self;
    [self.view addSubview:self.matchDetailTableView];
    
    self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 347)];
    //self.headerView.backgroundColor = [UIColor cyanColor];
    self.matchDetailTableView.tableHeaderView = self.headerView;
    [_matchDetailTableView release];
    [_headerView release];
    
    
#pragma mark 设计师头像按钮
    self.headButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //self.headButton.backgroundColor = [UIColor yellowColor];
    self.headButton.frame = CGRectMake(10, 17, 45, 45);
    self.headButton.layer.cornerRadius = 22.5;
    self.headButton.layer.masksToBounds = YES;
    
    //设计师头像
    
    [self.headButton sd_setBackgroundImageWithURL:[NSURL URLWithString:[self.matchModel.userImage objectForKey:@"large"]] forState:UIControlStateNormal];
    
    [self.headButton addTarget:self action:@selector(headClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.headerView addSubview:self.headButton];
#pragma mark 设计师名称
    self.stylistName = [[UILabel alloc] initWithFrame:CGRectMake(62, 30, 130, 20)];
    //self.stylistName.backgroundColor = [UIColor blueColor];
    [self.headerView addSubview:self.stylistName];
    
    //传值
    self.stylistName.text = self.matchModel.userName;
    //NSLog(@"%@",self.matchModel.userName);
    
    [_stylistName release];
#pragma mark 房屋大图片
    self.homeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 80, WIDTH, 240 )];
    //self.homeImageView.backgroundColor = [UIColor redColor];
    [self.headerView addSubview:self.homeImageView];
    
    //传值
    NSString *picUrlStr = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w%@_h%@_m0.jpg", self.matchModel.bId, self.matchModel.width, self.matchModel.height];
    //NSLog(@"%@",picUrlStr);
    
    [self.homeImageView sd_setImageWithURL:[NSURL URLWithString:picUrlStr]];
    
    
    
    
    
    
    
    
    
    
    
    
    
}

#pragma mark tableView协议
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuse = @"reuse";
    MatchDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[[MatchDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
    }
    //cell.textLabel.text = @"评论123";
    return cell;
}
#pragma mark 设计师头像点击方法
- (void)headClick:(UIButton *)button {
    NSLog(@"设计师头像button");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
